<template>
	<om-addpage style="padding-top: 35px;" :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit">
		<om-autoform  ref="autoform" :initConfigData="mainConfigData" :initValue="initValue"></om-autoform>
	</om-addpage>
</template>

<script>
	import {
		errorModal,
		ignoreHtml,
		getUrl,
		confirmModal,
		ptFloat,
		minusF
	} from '@/static/js/common.js';
	import {
		hasEditor,
		getEditorTitle,
		changeConfigAttr,
		buildFormData,
		formValidation,
		tranferToEditors,
		changeEditor,
		setSubmitSubValue,
		configSelectData,
		hasValue,
		formShowLoading,
		getFormFields,
		formModelLoad,
		getWorkCacheKey
	} from '@/static/js/formUtil.js';
	import moment from '@/static/js/moment.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildFormData({
				infonameIdCacheKey: 'hr-u-tlApproval-infonameId-cache',
				dateNum: 0,
				currentUserId: '',
				dzposId: '',
				readDataFlag: false,
				userIds: '',
				nowAttEndDate: '',
				isparentUser: 0,
				az: '',
				reasonList:[],
				disabledFlag: true,
			})
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId'])
		},
		methods:{
			canEditAttData(canEditFlag,checkEditFlag){
				let _that = this
				_that.om.request(
					"tlApproval/canEditAttData",
					{
						editFlag:canEditFlag,
						checkEditFlag: checkEditFlag,
					}
				).then(res=>{
					if (res.succeed) {
					    if (res.value) {
					        _that.disabledFlag = false;
					    }
					} 
				})
			},
			getPayStopYearMonth(){
				let _that = this
				_that.om.request(
					"tlApproval/getPayStopYearMonth"
				).then(res=>{
					_that.$refs.autoform.changeEditor("attendanceInfo","payStopYearMonth",'data',configSelectData(res,'text',"value"))
					_that.$refs.autoform.initSelectIndex("attendanceInfo","payStopYearMonth")
				})
			},
			getLeaveDeductionMonth(data){
				let _that = this
				_that.om.request(
					"tlApproval/getLeaveDeductionMonth",
					{
						effectDate:data
					}
				).then(res=>{
					// if(!_that.$refs.autoform.formdata.leaveDeductionMonth){
					// 	_that.$refs.autoform.formdata.leaveDeductionMonth = res.value.initData
					// }
					_that.$refs.autoform.changeEditor("attendanceInfo","leaveDeductionMonth",'data',configSelectData(res.value.initDataList,"text","value"))
					_that.$refs.autoform.initSelectIndex("attendanceInfo","leaveDeductionMonth")
				})
			},
			getYearMonth(date){
				let _that = this
				_that.om.request(
					"tlApproval/getYearMonth",
					{
						checkEditFlag: _that.checkedit,
						socialSecurityStopMonth: _that.$refs.autoform.formdata.socialSecurityStopMonth,
						providentFundStopMonth: _that.$refs.autoform.formdata.providentFundStopMonth,
						effectDate: date,
						userId: _that.$refs.autoform.formdata.infonameId
					}
				).then(res=>{
					// if(!_that.$refs.autoform.formdata.socialSecurityStopMonth){
					// 	_that.$refs.autoform.formdata.socialSecurityStopMonth = res.value.initData || ''
					// }
					// if(!_that.$refs.autoform.formdata.providentFundStopMonth){
					// 	_that.$refs.autoform.formdata.providentFundStopMonth = res.value.initData || ''
					// }
					_that.$refs.autoform.changeEditor("attendanceInfo","socialSecurityStopMonth","data",configSelectData(res.value.initDataList,"text","value"))
					_that.$refs.autoform.changeEditor("attendanceInfo","providentFundStopMonth","data",configSelectData(res.value.initDataList,"text","value"))
					_that.$refs.autoform.changeEditor("attendanceInfo","socialSecurityStopMonth",'type',"selectbox")
					_that.$refs.autoform.changeEditor("attendanceInfo","providentFundStopMonth",'type',"selectbox")
					_that.$refs.autoform.initSelectIndex("attendanceInfo","socialSecurityStopMonth")
					_that.$refs.autoform.initSelectIndex("attendanceInfo","providentFundStopMonth")
				})
			},
			findInstDirectorData(id){
				let _that = this
				_that.om.request(
					"tlApproval/findInstDirectorData",
					{
						userId: id
					},
					"post"
				).then(res=>{
					if(_that.subEditorObj["instDirectorInfo"]){
						_that.subEditorObj["instDirectorInfo"].workList = res.value
					}
				})
			},
			findBusinessDirectorData(){
				let _that = this
				_that.om.request('/tlApply/findBusinessDirectorData').then(res => {
					if(res.length>0){
						let sd = res								
						if(sd.length>0){
							let proArr = []
							for(let i=0; i<sd.length; i++){
								proArr.push(_that.om.request('tlApply/findBusinessDirectorInstList', { userId: sd[i].userId }))
							}
							
							Promise.all(proArr).then(res=>{
								for(let i=0; i<sd.length; i++){
									sd[i].businessDirectorId = sd[i].userId
									sd[i].businessDirectorName = sd[i].userName
									sd[i].interviewFlag = ''
									sd[i].interviewFlagName = ''
									sd[i].opinion = ''
									sd[i].instId = res[i][0].id
									sd[i].instName = res[i][0].instName
								}
								
								let dataList = _that._.cloneDeep(sd)
								if(_that.subEditorObj["businessDirectorInfo"]){
									_that.subEditorObj["businessDirectorInfo"].workList = dataList
									_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"businessDirectorStr",JSON.stringify(dataList))
									_that.$set(_that.formdata,'businessDirectorStr',JSON.stringify(dataList))
									_that.subEditorObj["businessDirectorInfo"].showAdd = false
									_that.subEditorObj["businessDirectorInfo"].showDel = false
								}
							})
						}else{
							_that.om.toast(res.msg);
						}
					}
				})
			},
			
			getWorkParam(){
				let _that = this
				return {
					infonameId:_that.$refs.autoform.formdata.infonameId
				}
			},
			verifySubDel2(index, editor){
				let _that = this
				_that.om.request('tlApproval/verifyRomveItem', {
					itemId: editor.workList[index].itemId,
				}).then(res => {
					if(res.succeed == true){
						_that.subEditorObj["handleInfo"].workList = editor.workList.filter(e => e.itemId != editor.workList[index].itemId) 
					}else{
						_that.om.toast(res.msg);
					}
				})
			},
			verifySubDel(index, editor){
				let _that = this
				if(editor.groupKey == 'handleInfo'){
					confirmModal(_that,"提示信息","确认删除交接项:"+editor.workList[index].itemName,()=>{
								_that.verifySubDel2(index, editor)
							},()=>{})
				}
				return false
			},
			
			ToText(HTML){
				var input = HTML;
				return input.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi,'').replace(/<[^>]+?>/g,'').replace(/\s+/g,' ').replace(/ /g,' ').replace(/>/g,' '); 
			},
			getLeaveApproveExMsg(id,ldate){
				let _that = this
				_that.om.request('/tlApproval/getLeaveApproveExMsg', {
					userId: id,
					leaveDate: ldate
				}).then(res => {
					if(res.succeed == true){
						_that.formdata.attExplain = res.value
						_that.$refs.autoform.formdata.attExplain = res.value
					}else{
						_that.om.toast(res.msg);
					}
				})
			},
			onSelectAttEndTime(time){
				let _that = this
				let title1 = _that.$refs.autoform.getEditorTitle("attendanceInfo","attEndTime")
				let title2 = _that.$refs.autoform.getEditorTitle("attendanceInfo","attEndDate")
				let title3 = _that.$refs.autoform.getEditorTitle("leaveInfo","effectDate")
				if(_that.$refs.autoform.formdata.attEndDate){
					if(moment(time).isBefore(_that.$refs.autoform.formdata.attEndDate,'day')){
						errorModal(_that,'提示信息',title1+'不能早于'+title2,()=>{
							_that.$refs.autoform.clear("attendanceInfo","attEndTime")
						})
					}
				}else{
					if(_that.$refs.autoform.formdata.effectDate){
						if(moment(time).isAfter(_that.$refs.autoform.formdata.effectDate,'day')){
							errorModal(_that,'提示信息',title1+'不能晚于'+title3,()=>{
								_that.$refs.autoform.clear("attendanceInfo","attEndTime")
							})
						}
					}
				}
			},
			onSelectAttEndDate(data){
				let _that = this
				let ldata = data.substring(0,10)
				let title1 = _that.$refs.autoform.getEditorTitle("attendanceInfo","attEndDate")
				let title2 = _that.$refs.autoform.getEditorTitle("leaveInfo","effectDate")
				 if(_that.$refs.autoform.formdata.effectDate){
					 if(moment(ldata).isAfter(_that.$refs.autoform.formdata.effectDate,'day')){
						 errorModal(_that,'提示信息', title1+'不能晚于' + title2,()=>{
						 	_that.$refs.autoform.clear('attendanceInfo','attEndDate')
						 })
					 }
				 }
			},
			onSelectZpos(data){
				let _that = this
				_that.dzposId = data.id
				_that.$refs.autoform.clear("userInfo","infonameId")
				_that.$refs.autoform.changeEditor("userInfo","infonameId",{
					link:"../../public/pageSearch/pageSearch",
					"linkParam": {
						other:JSON.stringify({
							posId: _that.dzposId,
							userId: _that.userId
						}),
						namefield:'userSalaryPosInstName',
						extrafield: 'parentInstName',
						searchfield:"q",
						initload:true,
						url:'tlApproval/getEmpList',
						cachename:_that.infonameIdCacheKey,
						placeholder:"请输入姓名"
					}
				})
			},
			leaveDayFunc(){
				let _that = this
				_that.formdata.leaveTypeId = _that.$refs.autoform.formdata.leaveTypeId
				if(_that.formdata.effectDate && _that.formdata.leaveTypeId == '4944'){
					uni.showModal({
						title: '',
						content: "'自动离职'旷工" + _that.dateNum + "天及以上的人员方能选择",
						showCancel: true,
						success(res){
							if(res.confirm){
								
							}else{
								_that.$refs.autoform.clear("leaveInfo","effectDate")
							}
						}
					})
				}
			},
			onSelectLeaveTypeCode(data){
				let _that = this
				if(data.id == '4944'){//自动离职
					//验证自动离职天数
					_that.leaveDayFunc()
				}else{
					//验证离职人员是否有请假记录
					_that.om.request('/tlApproval/verifyUser', {
						userId: _that.currentUserId
					}).then(res => {
						if(res.succeed == true){
							if(res.value){
								uni.showModal({
									title: '',
									content: res.value,
									showCancel: true,
									success(res){
										if(res.confirm){
											_that.leaveDayFunc()//验证自动离职天数
										}else{
											_that.$refs.autoform.clear("leaveInfo","leaveTypeId")
										}
									}
								})
							}else{
								_that.leaveDayFunc()//验证自动离职天数
							}
						}else{
							_that.om.toast(res.msg);
						}
					})
				}
			},
			onSelectEffectDate(data){
				let _that = this
				let dateOne = new Date(data).getTime();
				let dateBefore = new Date().getTime()-1000 * 60 * 60 * 24 * 30;
				let dateLast =new Date().getTime()+1000 * 60 * 60 * 24 * 30;
				// _that.$refs.autoform.formdata.attEndTime = data
				if(_that.$refs.autoform.formdata.attEndDate){
					let title1 = _that.$refs.autoform.getEditor("leaveInfo","effectDate")
					let title2 = _that.$refs.autoform.getEditor("attendanceInfo","attEndDate")
					if(moment(data).isBefore(_that.$refs.autoform.formdata.attEndDate)){
						errorModal(_that,'提示信息',title1+"不能早于"+title2,()=>{
							_that.$refs.autoform.clear("leaveInfo","effectDate")
							return
						})
						
					}
				}
				if(dateOne<dateBefore){
					uni.showModal({
						title: '',
						content: "选择日期已早于当前日期30天，是否确认？",
						showCancel: true,
						success(res){
							if(res.confirm){
								_that.getLeaveApproveExMsg(_that.userIds,data)
							}else{
								_that.$refs.autoform.clear("leaveInfo","effectDate")
							}
						}
					})
				}
				if(dateOne>dateLast){
					uni.showModal({
						title: '',
						content: "选择日期已晚于当前日期30天，是否确认？",
						showCancel: true,
						success(res){
							if(res.confirm){
								_that.getLeaveApproveExMsg(_that.userIds,data)
							}else{
								_that.$refs.autoform.clear("leaveInfo","effectDate")
							}
						}
					})
				}
				if(_that.formdata.leaveDate){
					let dateTwo = new Date(_that.formdata.leaveDate).getTime();
					if(dateOne < dateTwo){
						_that.om.toast('离职日期应大于等于申请离职日期');
					}else{
						_that.getLeaveApproveExMsg(_that.userIds,data)
					}
				}else{
					_that.getLeaveApproveExMsg(_that.userIds,data)
				}
				_that.getYearMonth(data)
				_that.getLeaveDeductionMonth(data)
				_that.getPayStopYearMonth()
			},
			getInfoFunc(userid,username){
				let _that = this
				let formdata = _that.$refs.autoform.formdata
				_that.userIds = userid
				
				_that.om.request('/temployee/getEmpBasicInfo', {
					userId: userid
				}).then(res => {
					if(res.succeed == true){
						let sd = res.value
						formdata.infonameId = userid
						formdata.infoname = username
						formdata.sexName = sd.sexName
						formdata.birthdate = sd.birthdate
						formdata.birthPlace = sd.birthPlace
						formdata.highestEduName = sd.highestEduName
						formdata.entrydate = sd.entrydate
						formdata.mobile = sd.mobile
						formdata.areaName = sd.areaName
						formdata.idTypeName = sd.idTypeName
						formdata.idcard = sd.idcard
						formdata.certificateValidDate = sd.certificateValidDate
						formdata.nationName = sd.nationName
						formdata.marriageName = sd.marriageName
						formdata.politicalName = sd.politicalName
						formdata.bloodTypeName = sd.bloodTypeName
						formdata.userno = sd.userno
						formdata.registerCategoryName = sd.registerCategoryName
						formdata.birthaddress = sd.birthaddress
						formdata.currentaddress = sd.currentaddress
						formdata.roleCategoryName = sd.roleCategoryName
						formdata.salaryPosName = sd.salaryPosName
						formdata.salarycatName = sd.salarycatName
						formdata.salaryPosInstName = sd.salaryPosInstName
						formdata.customCateAName = sd.customCateAName
						formdata.attributeName = sd.attributeName
						formdata.roleName = sd.roleName
						_that.om.request(
							"tinstitution/getInstInfo",
							{
								instId:sd.salaryPosInstId
							}
						).then(res=>{
							_that.$refs.autoform.formdata.instLevelId =  res.value.instcatId
							_that.$refs.autoform.formdata.instLevelName =  res.value.instcatName
						})
					}
				})
				_that.om.request('/tworkInfo/getInfo1', {
					userId: userid
				}).then(res => {
					if(res.succeed == true){
						let sd = res.value
						let dataList = _that._.cloneDeep(sd)
						_that.subEditorObj["workInfo"].workList = dataList
						_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"workInfo",JSON.stringify(dataList))
						_that.$set(_that.formdata,'workInfo',JSON.stringify(dataList))
						_that.subEditorObj["workInfo"].showAdd = false
						_that.subEditorObj["workInfo"].showDel = false
					}else{
						_that.om.toast(res.msg);
					}
				})
				_that.om.request('/employContractList/getContractInfo', {
					userId: userid
				}).then(res => {
					if(res.succeed == true){
						let sd = res.value
						if(sd.id){
							_that.readDataFlag = true
							formdata.laborTypeCode = sd.contractCategoryCode
							formdata.laborTypeName = sd.contractCategoryName
							formdata.contractTypeId = sd.contractTypeId
							formdata.contractTypeName = sd.contractTypeName
							formdata.laborNum = sd.num
							formdata.laborDate = sd.contractStartDate
							formdata.laborEnd = sd.contractEndDate
							_that.$refs.autoform.changeEditor("laborRelateInfo","laborTypeCode","type","labelbox")
							_that.$refs.autoform.changeEditor("laborRelateInfo","contractTypeId","type","labelbox")
							_that.$refs.autoform.changeEditor("laborRelateInfo","laborDate","type","labelbox")
							_that.$refs.autoform.changeEditor("laborRelateInfo","laborEnd","type","labelbox")
							_that.$refs.autoform.changeEditor("laborRelateInfo","laborNum","type","labelbox")
						}else{
							_that.readDataFlag = false
							_that.$refs.autoform.clear("laborRelateInfo","laborTypeCode")
							_that.$refs.autoform.clear("laborRelateInfo","contractTypeId")
							_that.$refs.autoform.clear("laborRelateInfo","laborDate")
							_that.$refs.autoform.clear("laborRelateInfo","laborEnd")
							_that.$refs.autoform.clear("laborRelateInfo","laborNum")
							_that.$refs.autoform.changeEditor("laborRelateInfo","laborTypeCode","type","selectbox")
							_that.$refs.autoform.changeEditor("laborRelateInfo","contractTypeId","type","selectbox")
							_that.$refs.autoform.changeEditor("laborRelateInfo","laborDate","type","datebox")
							_that.$refs.autoform.changeEditor("laborRelateInfo","laborEnd","type","datebox")
							_that.$refs.autoform.changeEditor("laborRelateInfo","laborNum","type","numberbox")
						}
					}else{
						_that.om.toast(res.msg);
					}
				})
				
				_that.om.request('/tlApproval/getLeaveType', {
					userId: userid,
					zuserId: _that.userId
				}).then(res => {
					_that.$refs.autoform.changeEditor("leaveInfo", "leaveTypeId", "data", configSelectData(res,"id","dicname"))
					_that.$refs.autoform.initSelectIndex("leaveInfo", "leaveTypeId")
				})
				
				_that.om.request('/tlApproval/getHamdleList', {
					leaveUserId: userid,
				}).then(res => {
					if(res.succeed == true){
						let sd = res.value
						let obj = {};
						let dataList = _that._.cloneDeep(sd)
						obj.data = dataList
						_that.subEditorObj["handleInfo"].workList = dataList
						_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"objStr",JSON.stringify(dataList))
						_that.$set(_that.formdata,'objStr',JSON.stringify(dataList))
						if(userid === _that.userId){
							obj.isDel = false
							_that.subEditorObj["handleInfo"].showAdd = false
							_that.subEditorObj["handleInfo"].showDel = false
						}else{
							obj.isDel = true
							_that.subEditorObj["handleInfo"].showAdd = true
							_that.subEditorObj["handleInfo"].showDel = true
						}
						uni.setStorageSync('hamdleListKey', obj)
					}else{
						_that.om.toast(res.msg);
					}
				})
			},
			formSubmit(){
				let _that = this
				_that.formdata.readDataFlag = _that.readDataFlag
				let arr = []
				_that.reasonList.forEach((item,i)=>{
					let editor = _that.$refs.autoform.getEditor("leaveReasonStrInfo",'leaveReasonSubId'+i)
					for(let d of editor.data){
						if(d.attr.checked){
							arr.push(d.value)
						}
					}
				})
				_that.formdata.leaveReasonIdStr = arr.toString()
				if(_that.checkedit){
					_that.formdata.editFlag = true
					if(_that.formdata.payStopFlag){
						_that.formdata.payStopFlag = true
					}else{
						_that.formdata.payStopFlag = false
					}
					_that.om.formSave('commonForm/doCheckOrApproveUpdate',_that.formdata,_that)
				}else{
					if(_that.edit){
						_that.om.formSave('tlApproval/addTlApproval',_that.formdata,_that)
					}else{
						_that.om.request(
							"posBusiAuth/verifyOne",
							{
								busCode:_that.busCode,
								isNew:true
							}
						).then(res=>{
							if(res.succeed){
								_that.$set(_that.formdata,'leaveReasonIdStr',arr.toString())
								_that.om.formSave('tlApproval/addTlApproval',_that.formdata,_that)
							}else{
								_that.om.toast(res.msg)
							}
						})
						
					}
				}
			},
			initLoad(options){
				let _that = this
				let ajaxArr = [
					urlUtil.zposUrl(options.code)
				]
				let fileId = options.fileId
				ajaxArr.push({
					url:"dictZero/getListByCode",
					param:{
						code:"37689"
					}
				},{
					url:"dataDict/getIntByCode",
					param:{
						code:"DD014003002"
					}
				},{
					url:"dictZero/findBooleanDtoList"
				},{
					url:"dictSource/loadCombo",
					param:{
						sourceId: "289",
						categoryId: "7172"
					}
				},{
					url:"commonForm/hasMainPos",
					param:{
						busCode:"HRS12"
					},
					method:'post'
				},{
					url:"commonForm/hasMainPos",
					param:{
						busCode:"HRS07"
					},
					method:'post'
				},
				{
					url:"tlApply/getReasonList",
					method:"post"
				}
				)
				if(fileId){
					ajaxArr.push({
						url:"tlApproval/getInfo",
						param:{
							id:fileId
						}
					})
				}
				if(options.checkedit){
					_that.checkedit = options.checkedit
					ajaxArr.push({
						url:"tlApproval/canEditAttData",
						param:{
							editFlag: _that.edit,
							checkEditFlag:_that.checkedit
						}
					})
				}
				formModelLoad(ajaxArr,function(res,mainData){ 
					changeEditor('topinfo', 'zposId', 'data', configSelectData(res[0], 'id', 'posname'), mainData);
					changeEditor("userInfo","infonameId",{
						link:"../../public/pageSearch/pageSearch",
						"linkParam": {
							other:JSON.stringify({
								posId: _that.dzposId,
								userId: _that.userId
							}),
							namefield:'userSalaryPosInstName',
							extrafield: 'parentInstName',
							searchfield:"q",
							initload:true,
							url:'tlApproval/getEmpList',
							cachename:_that.infonameIdCacheKey,
							placeholder:"请输入姓名"
						}
					},null,mainData)
					
					if(_that.subEditorObj["workInfo"]){
						let att = {
							showAdd:false,
							showDel:false
						}
						let configData = _that.subConfigData["workInfo"]
						if(hasEditor("workInfo","posName",configData)){
							let title = getEditorTitle("workInfo","posName",configData)
							att.titleTemplate = title+":<%= posName %>"
						}
						if(hasEditor("workInfo","salaryPosFlagStr",configData)){
							let title = getEditorTitle("workInfo","salaryPosFlagStr",configData)
							att.titleTemplate = att.titleTemplate+"<%= salaryPosFlagStr %>"
						}
						if(hasEditor("workInfo","parentUserName",configData)){
							let title = getEditorTitle("workInfo","parentUserName",configData)
							att.subtitle1Template = title+":<%= parentUserName %>"
						}
						if(hasEditor("workInfo","instShort",configData)){
							let title = getEditorTitle("workInfo","instShort",configData)
							att.subtitle1Template = att.subtitle1Template +'|'+  title +":<%= instShort %>"
						}
						if(hasEditor("workInfo","parentInst",configData)){
							let title = getEditorTitle("workInfo","parentInst",configData)
							att.subtitle2Template = title +":<%= parentInst %>"
						}
						if(hasEditor("workInfo","salaryWay",configData)){
							let title = getEditorTitle("workInfo","salaryWay",configData)
							att.subtitle2Template = (att.subtitle2Template?att.subtitle2Template +'|':'')+title +":<%= salaryWay %>"
						} 
						changeEditor("workInfo","workInfo",att,mainData)
					}
					// changeEditor("workInfo", "workInfo", {
					// 	titleTemplate: "  <%= posName %>",
					// 	subtitle1Template: "<%= instShort %>",
					// 	subtitle2Template: "<%= '计酬方式：'+ (salaryWay ? salaryWay : '') %>"
					// }, null, mainData)
					// _that.subEditorObj["workInfo"].showAdd = false
					// _that.subEditorObj["workInfo"].showDel = false
					if(_that.subEditorObj["handleInfo"]){
						changeEditor("handleInfo", "objStr", {
							getWorkParam:"getWorkParam",
							titleTemplate: "<%= itemName %>",
							subtitle1Template: "<%= '经办人：'+ (handleUserName ? handleUserName : '') %>",
						}, null, mainData)
						_that.subEditorObj["handleInfo"].showAdd = false
						_that.subEditorObj["handleInfo"].showDel = false
					}
					changeEditor("instDirectorInfo", "instDirectorStr", {
						showAdd:false,
						showDel:false,
						titleTemplate: "  <%= instDirectorName %>",
						subtitle1Template:"<%= '面谈：'+ (interviewFlag ? interviewFlagName : '') %>"
					}, null, mainData)
					
					changeEditor("businessDirectorInfo", "businessDirectorStr", {
						showAdd:false,
						showDel:false,
						titleTemplate: "  <%= businessDirectorName %>",
						subtitle1Template: "<%= '面谈：'+ (interviewFlag ? interviewFlagName : '') %>"
					}, null, mainData)
					uni.setStorageSync('isparentUserKey', 1)
					_that.dateNum = res[2].value
					changeEditor("laborRelateInfo", "laborTypeCode", "data", configSelectData(res[1],"id","dicname"),mainData)
					changeEditor("laborRelateInfo", "contractTypeId", "data", configSelectData(res[4],"id","text"),mainData)
					changeEditor("leaveInfo", "addUserFlag", "data", configSelectData(res[3],"value","name"),mainData)
					changeEditor("attendanceInfo","payStopFlag", "data", configSelectData(res[3],"value","name"),mainData)
					if(Object.prototype.toString.call(res[7].value) == "[object Array]"){
						let editors = []
						for(let i in res[7].value){
							let obj = {};
							obj.checkedit = true
							obj.data = configSelectData(res[7].value[i].children, "id", "text", true),
							obj.editReadonly = null
							obj.isfull = null
							obj.max = ''
							obj.min = ''
							obj.nameField = 'leaveReasonSubName'+i
							obj.required = false
							obj.title = res[7].value[i].text
							obj.type = 'checkbox'
							obj.valueField = 'leaveReasonSubId'+i
							editors.push(obj)
						}
						_that.reasonList = editors
						changeConfigAttr("leaveReasonStrInfo","editors",editors,mainData)
					}
					_that.$nextTick(function(){
						_that.$refs.autoform.initSelectVal("topinfo","zposId")
						_that.$refs.autoform.formdata.attEndDate = ''
					})
					if(fileId){
						var fieldArr = getFormFields(mainData)
						fieldArr.push("id","zuserId")
						_that.currentUserId = res[8].value.tlApproval.infonameId
						for(let i in  res[8].value.temployeeResponse){
							if(fieldArr.includes(i)){
								_that.$refs.autoform.$set(_that.$refs.autoform.formdata,i,res[8].value.temployeeResponse[i])
								_that.$set(_that.formdata,i,res[8].value.temployeeResponse[i])
							}
						}
						
						for(let i in  res[8].value.tlApproval){
							if(fieldArr.includes(i)){
								_that.$refs.autoform.$set(_that.$refs.autoform.formdata,i,res[8].value.tlApproval[i])
								_that.$set(_that.formdata,i,res[8].value.tlApproval[i])
							}
						}
						_that.readDataFlag = res[8].value.tlApproval.readDataFlag
						if(_that.readDataFlag){
							changeEditor("laborRelateInfo","laborTypeCode","type","labelbox",mainData)
							changeEditor("laborRelateInfo","contractTypeId","type","labelbox",mainData,mainData)
							changeEditor("laborRelateInfo","laborDate","type","labelbox",mainData)
							changeEditor("laborRelateInfo","laborEnd","type","labelbox",mainData)
							changeEditor("laborRelateInfo","laborNum","type","labelbox",mainData)
						}else{
							changeEditor("laborRelateInfo","laborTypeCode","type","selectbox",mainData)
							changeEditor("laborRelateInfo","contractTypeId","type","selectbox",mainData)
							changeEditor("laborRelateInfo","laborDate","type","datebox",mainData)
							changeEditor("laborRelateInfo","laborEnd","type","datebox",mainData)
							changeEditor("laborRelateInfo","laborNum","type","numberbox",mainData)
						}	
						for(let i in  res[8].value.tuserInfo){
							if(fieldArr.includes(i)){
								_that.$refs.autoform.$set(_that.$refs.autoform.formdata,i,res[8].value.tuserInfo[i])
								_that.$set(_that.formdata,i,res[8].value.tuserInfo[i])
							}
						}
						
						let dataList = _that._.cloneDeep(res[8].value.tworkInfos)
						_that.subEditorObj["workInfo"].workList = dataList
						_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"workInfo",JSON.stringify(dataList))
						_that.$set(_that.formdata,'workInfo',JSON.stringify(dataList))
						delete res[8].value.tworkInfos
						
						let obj = {}
						let dataList1 = _that._.cloneDeep(res[8].value.tlApproval_handles)
						obj.data = dataList1
						_that.subEditorObj["handleInfo"].workList = dataList1
						_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"objStr",JSON.stringify(dataList1))
						_that.$set(_that.formdata,'objStr',JSON.stringify(dataList1))
						delete res[8].value.tlApproval_handles
						
						if(_that.$refs.autoform.formdata.infonameId === _that.userId){
							obj.isDel = false
							_that.subEditorObj["handleInfo"].showAdd = false
							_that.subEditorObj["handleInfo"].showDel = false
						}else{
							obj.isDel = true
							_that.subEditorObj["handleInfo"].showAdd = true
							_that.subEditorObj["handleInfo"].showDel = true
						}
						uni.setStorageSync('hamdleListKey', obj)
						
						_that.formdata.id = fileId
						_that.$refs.autoform.formdata.id = fileId
						if(res[8].value.dataList){
							let cReasonList = _that._.cloneDeep(_that.reasonList) 
							for(let rtItem of res[8].value.dataList){
								for(let index in cReasonList){
									let arr = []
									cReasonList[index].data.forEach((item,i)=>{
										if(rtItem.leaveReasonId == item.value){
											_that.$set(item.attr,"checked",true)
											arr.push(rtItem.leaveReasonId)
										}
										if(_that.checkedit){
											if(_that.userId != _that.$refs.autoform.formdata.infonameId){
												_that.$set(item,"disabled",true)
											}else{
												_that.$set(item,"disabled",false)
											}
										}
									})
									_that.$refs.autoform.formdata['leaveReasonSubId'+index] = arr.toString()
								}
							}
							changeConfigAttr("leaveReasonStrInfo","editors",cReasonList,mainData)
						}
						if(_that.subEditorObj["businessDirectorInfo"]){
							let businessDirectorList = _that._.cloneDeep(res[8].value.businessDirectorList)
							_that.subEditorObj["businessDirectorInfo"].workList = businessDirectorList
							_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"businessDirectorStr",JSON.stringify(businessDirectorList))
							_that.$set(_that.formdata,"businessDirectorStr",JSON.stringify(businessDirectorList))
						}
						
						if(_that.subEditorObj["instDirectorInfo"]){
							let instDirectorList = _that._.cloneDeep(res[8].value.instDirectorList)
							_that.subEditorObj["instDirectorInfo"].workList = instDirectorList
							_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"instDirectorStr",JSON.stringify(instDirectorList))
							_that.$set(_that.formdata,"instDirectorStr",JSON.stringify(instDirectorList))
						}
						_that.om.request('/tlApproval/getLeaveType', {
							userId:_that.$refs.autoform.formdata.infonameId,
							zuserId: _that.$refs.autoform.formdata.zuserId
						}).then(res => {
							_that.$refs.autoform.changeEditor("leaveInfo", "leaveTypeId", "data", configSelectData(res,"id","dicname"))
							_that.$refs.autoform.initSelectIndex("leaveInfo", "leaveTypeId")
						})
						_that.getYearMonth(_that.$refs.autoform.formdata.effectDate)
						_that.getPayStopYearMonth()
						_that.getLeaveDeductionMonth(_that.$refs.autoform.formdata.effectDate)
						changeEditor("userInfo","infonameId","type","labelbox",mainData)
						if(!_that.checkedit){
							changeEditor("attendanceInfo","attEndDate","type","labelbox",mainData)
							changeEditor("attendanceInfo","attHours","type","labelbox",mainData)
							changeEditor("attendanceInfo","attDays","type","labelbox",mainData)
							changeEditor("attendanceInfo","payStopFlag","type","labelbox",mainData)
							changeEditor("attendanceInfo","attRemark","type","labelbox",mainData)
						}
						_that.$nextTick(function(){
							_that.$refs.autoform.formdata.infonameId = res[8].value.tlApproval.infonameId
							_that.$refs.autoform.formdata.infoname = res[8].value.tlApproval.infoname
							_that.$refs.autoform.initSelectIndex("leaveInfo", "addUserFlag")
							_that.nowAttEndDate = res[8].value.tlApproval.attEndDate
							if(res[5].value == true || res[6].value == true){
								if(!_that.nowAttEndDate){
									_that.$refs.autoform.formdata.attEndDate = ''
								}else{
									_that.$refs.autoform.formdata.attEndDate = _that.nowAttEndDate
								}
							}else{
								if(!_that.nowAttEndDate){
									_that.$refs.autoform.formdata.attEndDate = ''
								}else{
									_that.$refs.autoform.formdata.attEndDate = _that.nowAttEndDate
								}
							}
							if(!_that.readDataFlag){
								_that.$refs.autoform.initSelectIndex("laborRelateInfo", "laborTypeCode")
								_that.$refs.autoform.initSelectIndex("laborRelateInfo", "contractTypeId")
							}	
							_that.$refs.autoform.initSelectIndex("attendanceInfo","payStopFlag")
						})
					}
					if(_that.checkedit){
						let zobj = {}
						let dlist = _that._.cloneDeep(_that.subEditorObj["handleInfo"].workList)
						let dlist2 = _that._.cloneDeep(_that.subEditorObj["workInfo"].workList)
						zobj.data = dlist
						if(dlist2.length>0){
							let zd = 0;
							for(let zi=0; zi<dlist2.length; zi++){
								if(dlist2[zi].parentUserId == _that.userId && dlist2[zi].salaryPosFlag == true){
									_that.isparentUser = 1
									zd = 1
								}
							}
							if(zd == 1){
								uni.setStorageSync('isparentUserKey', 1)
								zobj.isDel = true
								_that.subEditorObj["handleInfo"].showAdd = true
								_that.subEditorObj["handleInfo"].showDel = true
							}else{
								uni.setStorageSync('isparentUserKey', 0)
								zobj.isDel = false
								_that.subEditorObj["handleInfo"].showAdd = false
								_that.subEditorObj["handleInfo"].showDel = false
							}						
							uni.setStorageSync('hamdleListKey', zobj)
						}
						_that.nowAttEndDate = res[8].value.tlApproval.attEndDate
						if(res[9].succeed == true&&res[9].value==true ){
							if(!_that.nowAttEndDate){
								_that.$refs.autoform.formdata.attEndDate = ''
							}else{
								_that.$refs.autoform.formdata.attEndDate = _that.nowAttEndDate
							}
							_that.$refs.autoform.initSelectIndex("attendanceInfo","payStopFlag")
						}else{
							if(!_that.nowAttEndDate){
								_that.$refs.autoform.formdata.attEndDate = ''
							}else{
								_that.$refs.autoform.formdata.attEndDate = _that.nowAttEndDate
							}
							changeEditor("attendanceInfo","attEndDate","type","labelbox",mainData)
							changeEditor("attendanceInfo","attHours","type","labelbox",mainData)
							changeEditor("attendanceInfo","attDays","type","labelbox",mainData)
							changeEditor("attendanceInfo","payStopFlag","type","labelbox",mainData)
							changeEditor("attendanceInfo","attRemark","type","labelbox",mainData)
							}
					}
				},options)
			}
		},
		onLoad(options) {
			let _that = this
			_that.initLoad(options)
		},
		onShow() {
			let _that = this
			for (let fieldId in _that.subEditorObj) {
				let editor = _that.subEditorObj[fieldId];
				uni.getStorage({
					key: getWorkCacheKey(fieldId),
					success: function(res) {
						if(fieldId == 'handleInfo'){
							let obj = {}
							let dataList1 = _that._.cloneDeep(res.data)
							obj.data = dataList1
							obj.isDel = uni.getStorageSync('hamdleListKey').isDel
							uni.setStorageSync('hamdleListKey', obj)
						}
						editor.workList = res.data;
						uni.removeStorage({
							key: getWorkCacheKey(fieldId)
						});
					}
				});
			}
			if(_that.$refs.autoform){
				uni.getStorage({
					key: _that.infonameIdCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							_that.$refs.autoform.clearGroup("leaveInfo")
							_that.currentUserId = d.id
							uni.setStorageSync('currentUserIdKey', d.id)
							_that.om.request('/tlApproval/verifySame', {
								userId: d.id,
								editId: ''
							}).then(res => {
								if(res.succeed == true){
									if(res.value){
										if(res.value.one){
											_that.om.toast(res.value.one);
										}else if(res.value.two){
											uni.showModal({
												title: '提示信息',
												content: _that.ToText(res.value.two),
												showCancel: true,
												success(sres){
													if(sres.confirm){
														_that.om.request('/tlApproval/verifySame1', {
															userId: d.id
														}).then(zres => {
															if(zres.succeed == true){
																_that.findInstDirectorData(d.id)
																_that.findBusinessDirectorData()
																if(zres.value && zres.value.two){
																	uni.showModal({
																		title: '',
																		content: _that.ToText(zres.value.two),
																		showCancel: true,
																		success(lres){
																			if(lres.confirm){
																				let cReasonList = _that._.cloneDeep(_that.reasonList)
																				for(let rItem of cReasonList){
																					for(let item of rItem.data){
																						_that.$set(item,"disabled",false)
																					}
																				}
																				_that.$refs.autoform.changeConfigAttr("leaveReasonStrInfo","editors",cReasonList)
																				_that.getInfoFunc(d.id,d.username)
																			}
																		}
																	})
																}else{
																	let cReasonList = _that._.cloneDeep(_that.reasonList)
																		for(let rItem of cReasonList){
																			for(let item of rItem.data){
																				_that.$set(item,"disabled",false)
																			}
																		}
																		_that.$refs.autoform.changeConfigAttr("leaveReasonStrInfo","editors",cReasonList)
																	_that.getInfoFunc(d.id,d.username)
																}
															}
														})
													}
												}
											})
										}else{
											if(res.value.t.leaveDate){
												if(res.value.dataList){
													let cReasonList = _that._.cloneDeep(_that.reasonList) 
													let list = []
													for(let rtItem of res.value.dataList){
														for(let rItem of cReasonList){
															rItem.data.forEach((item,i)=>{
																if(rtItem.leaveReasonId == item.value){
																	_that.$set(item.attr,"checked",true)
																	list.push(rtItem.leaveReasonId)
																}
															})
														}
													}
													_that.$refs.autoform.formdata.leaveReasonIdStr = list.toString()
													_that.$refs.autoform.changeConfigAttr("leaveReasonStrInfo","editors",cReasonList)
												}
												if(_that.subEditorObj["businessDirectorInfo"]){
													_that.subEditorObj["businessDirectorInfo"].workList = res.value.businessDirectorList
													
												}
												if(	_that.subEditorObj["instDirectorInfo"]){
													_that.subEditorObj["instDirectorInfo"].workList = res.value.instDirectorList
												}
												formdata.leaveDate = res.value.t.leaveDate
												formdata.effectDate = res.value.t.leaveDate
												_that.getLeaveApproveExMsg(d.id,res.value.t.leaveDate)
											}
											_that.getInfoFunc(d.id,d.username)
										}
									}else{
										_that.getInfoFunc(d.id,d.username)
									}
								}
							})
							uni.removeStorage({
								key: _that.infonameIdCacheKey
							});
						}
					},
				})
			}
		}
	}
</script>
<style></style>                                                                                                                                                                                                                                                                                                                  
